
const { ccclass, property } = cc._decorator;

@ccclass
export default class BaseItem extends cc.Component {

    private viewNode: cc.Node = null;
    private viewNodeWorldSpsceV2: cc.Vec2 = null;
    private viewNodeHeight: number = 0;
    private eventsetViewNode = null;

    onLoad() {
        this.viewNode = cc.find("Canvas");
        this.setViewNode();
    }
    update(dt) {
        if (!this.viewNode || !this.viewNode.isValid) return;
        let selfV2 = this.node.convertToWorldSpaceAR(cc.v2());
        /**/
        if ((selfV2.y - this.node.anchorY * this.node.height) > this.viewNodeWorldSpsceV2.y + this.viewNode.height / 2
            || selfV2.y + (1 - this.node.anchorY) * this.node.height < this.viewNodeWorldSpsceV2.y - this.viewNode.height) {//* 3 / 2
            this.node.children[0].active = false;
        } else {
            this.node.children[0].active = true;
        }
    }
    setViewNode() {
        if (!this.viewNode || !this.viewNode.isValid) return;
        let wordV2 = this.viewNode.convertToWorldSpaceAR(cc.v2());
        this.viewNodeWorldSpsceV2 = cc.v2(wordV2.x, wordV2.y);
        this.viewNodeHeight = this.viewNode.height;
    }
    public initViewNode(node: cc.Node) {
        if (!node) return false;
        this.viewNode = node;
        return true;
    }
}
